<?php

namespace app\common\model;

use app\common\library\Kdniao;
use think\Model;


class OrderShipping extends Model
{

    

    

    // 表名
    protected $name = 'order_shipping';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
	
	
	/**
	 * 获取物流信息
	 * @param $orderId 订单ID
	 * @return bool|mixed
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function getShipping($orderId) {
		$row = $this->alias('os')
			->join('shipping s', 'os.shipping_id = s.id', 'left')
			->where('os.order_id', $orderId)
			->field('s.code, os.shipping_no')
			->find();
		if(!$row) {
			$this->error = '没有发货信息';
			return false;
		}
		
		$obj = new Kdniao();
		return $obj->getOrderTracesByJson($row['code'], $row['shipping_no']);
	}





}
